#ifndef PITA_LIBRARY_H_
#define PITA_LIBRARY_H_

#include <boost/filesystem.hpp>
#include <boost/shared_ptr.hpp>

#include "exceptions.h"
#include "sqlite3pp/sqlite3pp.h"

class sqlite3;

namespace pita
{

	class Library
	{
		public:
			class DBError : public Exception {};

			Library(const boost::filesystem::path& root,
					const boost::filesystem::path& dbpath);

			void update();

			class iterator
			{
				public:
					iterator();
					iterator(sqlite3pp::database& db);

					void operator++();
					bool operator!=(const iterator&) const;
					bool operator==(const iterator&) const;

					std::string path() const;
					std::time_t modtime() const;

				private:
					bool atEnd() const;

				private:
					boost::shared_ptr<sqlite3pp::query> m_query;
					sqlite3pp::query::iterator m_iterator;
			};

			iterator begin() const;
			iterator end() const;

		private:
			void initDB();
			void checkDirectory(const boost::filesystem::path& root,
								const boost::filesystem::path& dir);
			void handleFile(const boost::filesystem::path& root,
							const boost::filesystem::path& file);

		private:
			boost::filesystem::path root_;
			sqlite3pp::database db_;
	};
	
}

#endif
